#!/usr/bin/env python3
"""
检查furniture表的详细结构
"""

import pymysql

def check_table_structure():
    try:
        # 连接到houseDB数据库
        connection = pymysql.connect(
            host='47.115.144.218',
            user='root',
            password='clannad123',
            port=3306,
            database='houseDB'
        )
        
        cursor = connection.cursor()
        
        # 查看furniture表结构
        cursor.execute("DESCRIBE furniture")
        columns = cursor.fetchall()
        print("📋 furniture表结构:")
        for column in columns:
            print(f"  - {column[0]} ({column[1]}) - {column[2]} - 默认值: {column[4]}")
        
        # 查看表创建语句
        cursor.execute("SHOW CREATE TABLE furniture")
        create_table = cursor.fetchone()
        print(f"\n📋 创建表的SQL:")
        print(create_table[1])
        
        # 查看表中的数据
        cursor.execute("SELECT COUNT(*) FROM furniture")
        count = cursor.fetchone()
        print(f"\n📊 表中的记录数: {count[0]}")
        
        if count[0] > 0:
            cursor.execute("SELECT * FROM furniture LIMIT 3")
            rows = cursor.fetchall()
            print("📋 前3条记录:")
            for row in rows:
                print(f"  {row}")
        
        cursor.close()
        connection.close()
        
    except Exception as e:
        print(f"❌ 检查表结构失败: {e}")

if __name__ == "__main__":
    check_table_structure()
